<?php
require_once MDL_TABLES;
$tables = getTables ();

if (isset ($_SESSION[KEY_SESSION_USER])) {
    require_once CLASS_USER;
    $user = unserialize ($_SESSION[KEY_SESSION_USER]);
    $logged = $user->isRegistered ();
} else {
    $logged = false;
}
?>
<div id="menu">
    <hr />
    <ul>
        <li <?php if (isset ($request) && $request == 'delete') echo 'id="active"'; ?>>
            <a href="<?php echo HTTP_CTRL_MAIN . '?request=delete'; ?>"><strong>Elimina</strong></a>
            <ul>
                <?php foreach ($tables as $key => $tab) : if ($logged && $user->can ('delete', $key)) : ?>
                        <li><a href="<?php echo HTTP_CTRL_MAIN . "?request=delete&table=$key"; ?>"><?php echo $tab; ?></a></li>
                    <?php endif;
                endforeach;
                ?>
            </ul>
        </li>
        <li <?php if (isset ($request) && $request == 'insert') echo 'id="active"'; ?>>
            <a href="<?php echo HTTP_CTRL_MAIN . '?request=insert'; ?>"><strong>Inserisci</strong></a>
            <ul>
                <?php foreach ($tables as $key => $tab) : if ($logged && $user->can ('insert', $key)) : ?>
                        <li><a href="<?php echo HTTP_CTRL_MAIN . "?request=insert&table=$key"; ?>"><?php echo $tab; ?></a></li>
                    <?php endif;
                endforeach;
                ?>
            </ul>
        </li>
        <li <?php if (isset ($request) && $request == 'edit') echo 'id="active"'; ?>>
            <a href="<?php echo HTTP_CTRL_MAIN . '?request=edit'; ?>"><strong>Modifica</strong></a>
            <ul>
                <?php foreach ($tables as $key => $tab) : if ($key == 'permesso') continue; if ($logged && $user->can ('edit', $key)) : ?>
                        <li><a href="<?php echo HTTP_CTRL_MAIN . "?request=edit&table=$key"; ?>"><?php echo $tab; ?></a></li>
    <?php endif;
endforeach;
?>
            </ul>
        </li>
        <li <?php if (isset ($request) && $request == 'view') echo 'id="active"'; ?>>
            <a href="<?php echo HTTP_CTRL_MAIN . '?request=view'; ?>"><strong>Visualizza</strong></a>
            <ul>
                <?php foreach ($tables as $key => $tab) : if ($logged && $user->can ('view', $key)) : ?>
                        <li><a href="<?php echo HTTP_CTRL_MAIN . "?request=view&table=$key"; ?>"><?php echo $tab; ?></a></li>
    <?php endif;
endforeach;
?>
            </ul>
        </li>
        <li <?php if (isset ($stat)) echo 'id="active"'; ?>>
            <a href="<?php echo HTTP_CTRL_MAIN . '?stat='; ?>"><strong>Statistiche</strong></a>
            <ul>
<?php foreach ($tables as $key => $tab) : ?>
                    <li><a href="<?php echo HTTP_CTRL_MAIN . "?stat=$key"; ?>"><?php echo $tab; ?></a></li>
        <?php endforeach; ?>
            </ul>
        </li>
        <?php
        if ($logged) :
            ?>
            <li><a href="<?php echo HTTP_CTRL_MAIN; ?>?account=logout">Logout</a></li>
            <?php
        endif;
        if (!$logged) :
            ?>
            <li><a href="<?php echo HTTP_CTRL_MAIN; ?>?account=login">Login</a></li>
<?php endif; ?>
    </ul>

</div>